//
//  UIView+Nib.m
//  jobClient
//
//  Created by 一览ios on 2017/9/20.
//  Copyright © 2017年 YL1001. All rights reserved.
//

#import "UIView+Nib.h"

@implementation UIView (Nib)

+ (UINib *)loadNib {
    return [self loadNibNamed:NSStringFromClass([self class])];
}

+ (UINib *)loadNibNamed:(NSString*)nibName {
    return [self loadNibNamed:nibName bundle:[NSBundle mainBundle]];
}

+ (UINib *)loadNibNamed:(NSString*)nibName bundle:(NSBundle *)bundle {
    return [UINib nibWithNibName:nibName bundle:bundle];
}



+ (instancetype)loadInstanceFromNib {
    return [self loadInstanceFromNibWithName:NSStringFromClass([self class])];
}

+ (instancetype)loadInstanceFromNibWithName:(NSString *)nibName {
    return [self loadInstanceFromNibWithName:nibName owner:nil];
}

+ (instancetype)loadInstanceFromNibWithName:(NSString *)nibName owner:(id)owner {
    return [self loadInstanceFromNibWithName:nibName owner:owner bundle:[NSBundle mainBundle]];
}

+ (instancetype)loadInstanceFromNibWithName:(NSString *)nibName owner:(id)owner bundle:(NSBundle *)bundle {
    UIView *result = nil;
    NSArray* elements = [bundle loadNibNamed:nibName owner:owner options:nil];
    for (id object in elements) {
        if ([object isKindOfClass:[self class]]) {
            result = object;
            break;
        }
    }
    return result;
}


- (CGFloat)kCornerRadius {
    return self.layer.cornerRadius;
}
- (void)setKCornerRadius:(CGFloat)kCornerRadius {
    self.layer.cornerRadius = kCornerRadius;
    self.layer.masksToBounds = (kCornerRadius > 0);
}

- (CGFloat )kBorderWidth {
    return self.layer.borderWidth;
}
- (void)setKBorderWidth:(CGFloat)kBorderWidth {
    self.layer.borderWidth = kBorderWidth;
}

- (UIColor *)gBorderColor {
    return [UIColor colorWithCGColor:self.layer.borderColor];
}
- (void)setGBorderColor:(UIColor *)gBorderColor {
    self.layer.borderColor = [gBorderColor CGColor];
}

@end
